﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Web.fanliAdmin.Info
{
    public partial class fanli_helpcata : System.Web.UI.Page
    {
        #region DAL
        fanli.DAL.fanli_helpcata dal = new fanli.DAL.fanli_helpcata();
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionHelp.AssertLogin(this);
            if (!IsPostBack)
            {
                GridBind();
            }
        }

        private void GridBind()
        {
            StringBuilder sql = new StringBuilder();
            List<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter param = null;
            sql.Append("select * from fanli_helpcata where 1=1 ");

            if (txtQryCataname.Text != "")
            {
                sql.Append(" and cataname like '%' + @cataname + '%'");
                param = new SqlParameter("@cataname", txtQryCataname.Text);
                paramList.Add(param);
            }
            sql.Append(" order by sortID ");

            DataSet ds = dal.GetDatasetBySql(sql.ToString(), paramList);
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;
            pds.AllowPaging = true;
            AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.PageSize = AspNetPager1.PageSize;
            this.GridView1.DataSource = pds;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#E9F5FC'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
            }
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            GridBind();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
            if (dal.Delete(id) > 0)
            {
                GridBind();
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            GridBind();
        }
    }
}